package com.notice.mapper;

import com.order.hit.crossover.platform.common.bean.Notice;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface NoticeMapper
{
    @Select("SELECT * FROM notice")
    @Results({
            @Result(property = "noticeId", column = "notice_id"),
            @Result(property = "noticeInfo", column = "notice_info"),
            @Result(property = "noticeState", column = "notice_state"),
            @Result(property = "noticeType", column = "notice_type"),
            @Result(property = "noticeTime", column = "notice_time"),
            @Result(property = "storeId", column = "store_id")
    })
    List<Notice> selectAll();


    @Select("SELECT * FROM notice where notice_id = #{noticeId}")
    @Results({
            @Result(property = "noticeId", column = "notice_id"),
            @Result(property = "noticeInfo", column = "notice_info"),
            @Result(property = "noticeState", column = "notice_state"),
            @Result(property = "noticeType", column = "notice_type"),
            @Result(property = "noticeTime", column = "notice_time"),
            @Result(property = "storeId", column = "store_id")
    })
    Notice selectbyNoticeId(@Param("noticeId")Long noticeId);


    @Select("SELECT * FROM notice where store_id = #{storeId} and notice_type = #{noticeType} order by notice_id desc")
    @Results({
            @Result(property = "noticeId", column = "notice_id"),
            @Result(property = "noticeInfo", column = "notice_info"),
            @Result(property = "noticeState", column = "notice_state"),
            @Result(property = "noticeType", column = "notice_type"),
            @Result(property = "noticeTime", column = "notice_time"),
            @Result(property = "storeId", column = "store_id")
    })
        //  查询某个门店/顾客的所有通知
    List<Notice> selectbyStoreId(@Param("storeId")String storeId, @Param("noticeType")int noticeType);


    @Select("SELECT * FROM notice where store_id = #{storeId} and notice_type = #{noticeType} and notice_State = #{noticeState} " +
            "order by notice_id desc")
    @Results({
            @Result(property = "noticeId", column = "notice_id"),
            @Result(property = "noticeInfo", column = "notice_info"),
            @Result(property = "noticeState", column = "notice_state"),
            @Result(property = "noticeType", column = "notice_type"),
            @Result(property = "noticeTime", column = "notice_time"),
            @Result(property = "storeId", column = "store_id")
    })
        //  查询某个门店/顾客的某个状态的所有通知
    List<Notice> selectStatebyStoreId(@Param("storeId")String storeId, @Param("noticeState")int noticeState, @Param("noticeType")int noticeType);


    @Select("SELECT * FROM notice where store_id = #{storeId} " +
            "and notice_type = #{noticeType} and notice_state = #{noticeState}" +
            "order by notice_id desc")
    @Results({
            @Result(property = "noticeId", column = "notice_id"),
            @Result(property = "noticeInfo", column = "notice_info"),
            @Result(property = "noticeState", column = "notice_state"),
            @Result(property = "noticeType", column = "notice_type"),
            @Result(property = "noticeTime", column = "notice_time"),
            @Result(property = "storeId", column = "store_id")
    })
        //  查询某个门店的某个类型的某个状态的所有通知
    List<Notice> selectTypeStatebyStoreId(@Param("storeId")String storeId
            , @Param("noticeType")int noticeType, @Param("noticeState")int noticeState);


    @Insert("insert into notice(notice_info, notice_state, notice_type, notice_time, store_id) " +
            "values(#{noticeInfo}, #{noticeState}, #{noticeType}, sysdate(), #{storeId})")
    @Results({
            @Result(property = "noticeId", column = "notice_id"),
            @Result(property = "noticeInfo", column = "notice_info"),
            @Result(property = "noticeState", column = "notice_state"),
            @Result(property = "noticeType", column = "notice_type"),
            @Result(property = "noticeTime", column = "notice_time"),
            @Result(property = "storeId", column = "store_id")
    })
    void add(Notice notice);


    @Update("update notice set notice_info=#{noticeInfo}, notice_state=#{noticeState}, " +
            "notice_type=#{noticeType}, notice_time=#{noticeTime},store_id=#{storeId} " +
            "where notice_id = #{noticeId}")
    void update(Notice notice);

    @Update("update notice set notice_state = 1 " +
            "where notice_id = #{noticeId}")
    void updatestate(@Param("noticeId")Long noticeId);

    @Delete("delete from notice where notice_id = #{noticeId}")
    void deletebyNoticeId(@Param("noticeId")Long noticeId);

}
